# -*- coding:UTF-8 -*-
'''
Created on 2017年8月20日

@author: dayu
'''
import unittest
from createList.JGListCreator import JGListCreator as Creator

class Test(unittest.TestCase):


    def setUp(self):
        self.creator = Creator()
        pass


    def tearDown(self):
        pass


    def testCreate(self):
        l = [1,2,3,4,5,6,7,8,9]
        self.creator.create(l)
        count = len(self.creator.serialization)
        print count
        self.assertLessEqual(362880, count, "Error created!")  
        pass
        
    def testhasFixNumbers(self):
#         numList = [1,2,3,4,5,6,7,9]
        posMap = {8: 3}
        self.creator.hasFixNumbers(posMap)
        count = len(self.creator.serialization)
#         print self.creator.serialization[0]
        self.assertEqual(40320, count, "Error created!")  
#         numList = [1,2,3,4,5,6,7,8,9]
        posMap = {}
        self.creator.hasFixNumbers(posMap)
        count = len(self.creator.serialization)
#         print self.creator.serialization[0]
        self.assertEqual(362880, count, "total -- Error created!") 
        pass
    def testridSome(self):
        return
#         numList = [1,2,3,4,5,6,7,8,9]
        posMap = {}
        self.creator.hasFixNumbers(posMap)
        posMap = {9: 1} 
        self.creator.ridSome(posMap)
        count = len(self.creator.serialization)
        print count
        self.assertEqual(362880 - 40320, count, "ridSome -- Error created!") 
    
    def testNext(self):
        l = [1,2,3,4,5,6,7,8,9]
        self.creator.create(l)
        ret = self.creator.next(1)
        print '----- next'
        ret = self.creator.next(2)
        print ret
        self.assertEqual(ret, [1, 2, 3, 4, 5, 6, 8, 9, 7], 'next method error')
        pass
    def testFirst(self):
        l = [1,2,3,4,5,6,7,8,9]
        self.creator.create(l)
        print '----- first'
        ret = self.creator.first()
        print ret
        self.assertEqual(ret, [1, 2, 3, 4, 5, 6, 7, 8, 9], 'first method error')
        pass
    def testLast(self):
        l = [1,2,3,4,5,6,7,8,9]
        self.creator.create(l)
        print '----- last'
        ret = self.creator.last()
        print ret
        self.assertEqual(ret, [9, 8, 7, 6, 5, 4, 3, 2, 1], 'last method error')
        pass
    def testverify(self):
        nine = [1,3,5,4,2,7,9,8,6]
        ret = self.creator.verify(nine)
        self.assertTrue(ret, 'verify failed')
        nine = [1,3,5,4,2,7,9,6,6]
        ret = self.creator.verify(nine)
        self.assertFalse(ret, 'verify failed')
        nine = [1,3,5,4,2,7,9,8,6,10]
        ret = self.creator.verify(nine)
        self.assertFalse(ret, 'verify failed')
        nine = [1,3,5,4,2,7,9,8]
        ret = self.creator.verify(nine)
        self.assertFalse(ret, 'verify failed')
       
        
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testCreate']
    unittest.main()